package controllers;

import com.google.gson.reflect.TypeToken;
import play.*;
import play.mvc.*;

import java.util.*;
import models.*;
import play.mvc.Scope.Session;
import javax.swing.Timer;

import models.*;
//@With(Secure.class)
public class Application extends Controller {

        public static void index() {
                render();
        }

		public static void TMtest(){
			render();
		}

        public static void trips() {
                renderJSON(Trips.findAll());
        }

//        public static void authenticate(String login, String password) {
//                renderJSON(Security.authenticate(login, password));
//        }

        /**
         * PROV’s notification of availability. Now not use.
         **/
        public static void provDeclare(float Plat, float Plong, Float fareFixed, Float farePerMinute, long provId) {
                //Long provId = Long.parseLong(Session.current().get("id"));
                Trips trip = new Trips(provId, Plat, Plong);
                trip.save();
                StatusManager.get().provDeclared(provId, Plat, Plong);
                if (fareFixed != null) {
                        Provs prov = Provs.find("byID", provId).first();
                        prov.fareFixed = fareFixed;
                        prov.save();
                }
                if (farePerMinute != null) {
                        Provs prov = Provs.find("byID", provId).first();
                        prov.farePerMinute = farePerMinute;
                        prov.save();
                }

        }

        public static void client(){
				render();
		}

        public static void client(String deviceSn){
				render(deviceSn);
		}


        public static void provider() {
                render();
        }

		public static void provider(String login, String password) {
                render(login, password);
        }
        
        //For test
        public static void createProv(float pLat,float pLong){
                long provId;
                Provs provider = new Provs();
                provider.login = "test"+Provs.count();
                provider.password = "test";
                provider.save();
                provId = provider.id;
                renderJSON(provId);
                //Session.current().put("provId",provider.id);

        }
		/**
         * Get all providers in JSON format
         * */

         public static void provs() {
                renderJSON(Provs.findAll());
        }

         public static void provRegistration(){
                 render();
         }

         public static void userRegistration(){
                 render();
         }
}
